<template>
    <el-dialog
        v-model="tenantDeleteDialogVisible"
        title="删除租户"
        width="20%"
        align-center
        :show-close="false"
        :close-on-click-modal="false"
    >
        是否确定删除？
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="cancelDialog()">取 消</el-button>
                <el-button type="primary" :loading="deleteLoading" @click="submitDialog()">
                    确认
                </el-button>
            </div>
        </template>
    </el-dialog>
</template>

<script name="TenantDeleteDialog" setup lang="ts">
import {ElNotification} from "element-plus";
import {tenantInfoDelete, tenantInfoQuery} from "@/request/tenant";
import {computed, defineProps, ref} from "vue";
import {useTenantInfoStore} from "@/stores/userInfo/tenantInfo";

let props = defineProps(['tenantDataForm']);

let tenantDataForm = computed(() => {return props['tenantDataForm']});

let deleteLoading = ref(false);

let tenantDeleteDialogVisible = computed(() => {return useTenantInfoStore().tenantDeleteDialog});
let tenantSearchData = computed(() => {return useTenantInfoStore().tenantSearchData});

function cancelDialog() {
    useTenantInfoStore().resetTenantDeleteDialog(false);
}

function submitDialog() {
    deleteLoading.value = true
    tenantInfoDelete(tenantDataForm.value).then(res => {
        if (res["code"] === '200') {
            ElNotification({
                title: 'Success',
                message: res["message"],
                type: 'success'
            });
            tenantInfoQuery(tenantSearchData.value).then(res => {
                useTenantInfoStore().resetTenantDataList(res.data);
            })
            useTenantInfoStore().resetTenantDeleteDialog(false);
        }
        deleteLoading.value = false
    }).catch(res => {
        deleteLoading.value = true
    })
}
</script>

<style scoped lang="less">

</style>